#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
class Solution {
public:
    int minimumTotal(vector<vector<int>>& triangle) {
       int m= triangle.size();
       for(int i=m-2;i>=0;i--)
       {
           for(int j=0;j<triangle[i].size();++j)
           triangle[i][j]+=min(triangle[i+1][j],triangle[i+1][j+1]);
       }
       return triangle[0][0];
    }
};
int main()
{
   Solution s;
   vector<vector<int>> m={{2},{3,4},{6,5,7},{4,1,8,3}};
   cout<<s.minimumTotal(m)<<endl;
   return 0;
}
